package com.hazardousholdings.unkj.validation;

public class MinimumValidator<T extends Comparable<? super T>> implements Validator<T> {

	private T minimum;
	private String invalidMessage;
	
	public MinimumValidator(T minimum) {
		this.minimum = minimum;
	}
	
	@Override
	public String getInvalidMessage() {
		if(this.invalidMessage == null) {
			return String.format("Input must be greater than or equal to %s", this.minimum);
		} else {
			return this.invalidMessage;
		}
	}

	@Override
	public void setInvalidMessage(String message) {
		this.invalidMessage = message;
	}

	@Override
	public ValidationResults<T> validate(T input) {
		if(input.compareTo(this.minimum) < 0) {	// input < low
			return new ValidationResults<T>(input, false, this.getInvalidMessage());
		} else {
			return new ValidationResults<T>(input, true);
		}
	}

}
